﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using SmartSpace.Core;

namespace WorkSpace.Core
{
    public class WorkSpaceContext : DomainContext
    {
        public WorkSpaceContext(DbContext dbContext)
            : base(dbContext)
        {

        }

        public static void Build(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Link>().ToTable("WSLink");
            modelBuilder.Entity<Link>().HasKey(p => p.Id);
            modelBuilder.Entity<Link>()
                .HasRequired<Category>(p => p.Category)
                .WithMany().HasForeignKey(p => p.CategoryId);

            modelBuilder.Entity<Category>().ToTable("WSCategory");
            modelBuilder.Entity<Category>().HasKey(p => p.Id);
            modelBuilder.Entity<Category>().Property(p => p.Id).IsRequired();

            modelBuilder.Entity<PersonalLink>().ToTable("WSPersonalLink");
            modelBuilder.Entity<PersonalLink>().HasKey(p => p.Id);
            modelBuilder.Entity<PersonalLink>()
                .HasRequired<Link>(p => p.Link)
                .WithMany().HasForeignKey(p => p.LinkId)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<PersonalPackage>().ToTable("WSPersonalPackage");
            modelBuilder.Entity<PersonalPackage>().HasKey(p => p.Id);

            modelBuilder.Entity<IconData>().ToTable("WSIconData");
            modelBuilder.Entity<IconData>().HasKey(p => p.Id);
        }
    }
}
